{ ROSFIL.INC - Remote Operating System: File Sub-system }

overlay procedure toggle_st_switch;
{ Toggle file size display }
  begin
    writeln(USR);
    st_switch := not st_switch;
    write(USR, 'File sizes will be shown in ');
    if st_switch
      then writeln(USR, 'bytes, where "k" is 1024.')
      else writeln(USR, 'minutes and seconds of transfer time.')
  end;

overlay procedure newin_list;
{ List new uploads }
  var
    i: integer;
    st: StrTAD;
    temp_user_rec: user_list;
  begin
    i := pred(FileSize(nwin_file));
    while (not brk) and (i >= 0) do
      begin
        seek(nwin_file, i);
        read(nwin_file, nwin_rec);
        with nwin_rec do
          begin
            if status = 1
              then
                begin
                  st := FormTAD(t);
                  GetRec(DatF, user, temp_user_rec);
                  writeln(USR);
                  writeln(USR, pad(name, 15), descr);
                  writeln(USR, '   ', pad(st, 30),
                    temp_user_rec.fn, ' ', temp_user_rec.ln)
                end
          end;
        i := pred(i)
      end
  end;

overlay procedure file_area_change(req: Str10);
{ View and set up file area for use }
  var
    i, Drive, User: integer;
    this: SectPtr;
    pr: StrPr;
  begin
    if req = ''
      then
        begin
          pr := 'File area: ';
          if user_rec.help_level > 0
            then insert(' [press "?" for menu]', pr, pos(':', pr));
          req := compress(prompt(pr, 10, 'ES?'))
        end;
    writeln(USR);
    while (not new_dir) and (req <> '') do
      begin
        this := SectBase;
        if req = '?'
          then
            begin
              writeln(USR, 'Available file areas:');
              writeln(USR);
              while (not brk) and (this <> nil) do
                begin
                  if user_rec.access >= this^.SectAccs
                    then writeln(USR, pad(this^.SectName, 14), this^.SectDesc);
                  this := this^.next
                end;
              writeln(USR);
              req := compress(prompt(pr, 10, 'ES?'));
              writeln(USR)
            end
        else if req <> ''
          then
            begin
              FindSect(req, Drive, User, OK);
              if OK
                then
                  begin
                    SectReq := req;
                    SetDrv  := Drive;
                    SetUsr  := User;
                    ReadDir(DirEntries, DirSpace, DirBase)
                  end
                else
                  begin
                    writeln(USR, '"', req, '" not found.  Available file areas:');
                    writeln(USR);
                    i := 0;
                    this := SectBase;
                    while (not brk) and (this <> nil) do
                      begin
                        if user_rec.access >= this^.SectAccs
                          then
                            begin
                              write(USR, pad(this^.SectName, 12));
                              i := succ(i);
                              if 0 = i mod 6
                                then writeln(USR)
                            end;
                        this := this^.next
                      end;
                    if 0 <> i mod 6
                      then writeln(USR);
                    writeln(USR);
                    req := compress(prompt(pr, 10, 'ES?'));
                    writeln(USR)
                  end
            end
      end
  end;

overlay procedure library;
{ Open and close a library }
  var
    i: integer;
    this: FilePtr;
  begin { library }
    if in_library
      then
        begin
          SetSect(SetDrv, SetUsr);          { Close file }
          Close(libr_file);
          SetSect(HomDrv, HomUsr);
          while LibBase <> nil do           { Clean out old list }
            begin
              this := LibBase;
              LibBase := LibBase^.Next;     { Go to next on chain }
              dispose(this)                 { Reclaim space }
            end;
          in_library := FALSE;
          writeln(USR, 'Library ', LibReq, ' closed.')
        end
      else
        begin
          LibReq := compress(prompt('Library: ', 12, 'ES'));
          writeln(USR);
          delete(LibReq, 1, pos(':', LibReq));
          if LibReq <> ''
            then
              begin
                if pos('.', LibReq) = 0
                  then LibReq := LibReq + '.LBR';
                if copy(LibReq, succ(pos('.', LibReq)), 3) = 'LBR'
                  then LibReadDir(LibEntries, LibSpace, LibBase);
                if not in_library
                  then writeln(USR, 'Cannot open ', LibReq, '.')
              end
        end
  end;

overlay procedure directory;
{ Display file area or library directory }
  var
    i, j, k, entries, rows, mm, ss, size: integer;
    this: FilePtr;
    nodes: array[1..columns] of FilePtr;
    st: Str10;
  begin
    writeln(USR);
    new_dir := FALSE;
    if in_library
      then
        begin
          this := LibBase;
          entries := LibEntries;
          if entries = 0
            then writeln(USR, '   Library: ', LibReq, ' is empty.')
            else writeln(USR, '   Library: ', LibReq, '   Files: ', entries,
                 '   Space used: ', LibSpace, 'k')
        end
      else
        begin
          this := DirBase;
          entries := DirEntries;
          if entries = 0
            then writeln(USR, '   File area: ', SectReq, ' is empty.')
            else write(USR, '   File area: ', SectReq, '   Files: ', entries,
                 '   Space used: ', DirSpace, 'k');
          if user_rec.access >= 200
            then writeln(USR, '   Free: ', free_space, 'k')
            else writeln(USR)
        end;
    if entries > 0
      then
        begin
          rows := entries div columns;
          if 0 <> entries mod columns
            then rows := succ(rows);
          nodes[1] := this;
          for i := 2 to columns do
            begin
              for j := 1 to rows do
                this := this^.next;
              nodes[i] := this
            end;
          i := 1;
          while (not brk) and (i <= rows) do
            begin
              for j := 1 to columns do
                begin
                  this := nodes[j];
                  if (i + rows * pred(j)) <= entries
                    then
                      begin
                        if st_switch
                          then
                            begin
                              size := this^.fsize shr 3;
                              if (this^.fsize mod 8) <> 0
                                then size := succ(size);
                              st := intstr(size, 4) + 'k '
                            end
                          else
                            begin
                              send_time(this^.fsize, mm, ss);
                              st := intstr(mm, 3) + ':' + intstr(ss, 2);
                              for k := 3 to length(st) do
                                if st[k] = ' '
                                  then st[k] := '0'
                            end;
                        write(USR, this^.fname, st);
                        if j < columns
                          then write(USR, fence, ' ')
                          else writeln(USR)
                      end
                    else writeln(USR);
                  nodes[j] := nodes[j]^.next   { Go to next on list }
                end;
              i := succ(i)
            end
        end;
    if j <> columns
      then writeln(USR)
  end;

