{ ROSMAIN.INC - Remote Operating System mainline code }

begin { ROS }
  system_init;
  cold_start;
  setup;
  wait_for_user;
  while not fini do
    begin
      login;
      mesg_area_change('POST');
      file_area_change('LOGIN');
      list('B');
      while online and in_use do
        begin
          timer(time_on, time_left);
          st := intstr(time_left, 1) + '-';
          case mode of
            message_mode: st := st + 'M:' + AreaReq;
            files_mode  : begin
                            st := st + 'F:' + SectReq;
                            if in_library
                              then st := st + ' [' + LibReq + '] ';
                            if new_dir
                              then directory;
                            if up_down_display
                              then
                                begin
                                  up_down_display := FALSE;
                                  writeln(USR, user_rec.upload, ' uploads, ',
                                    user_rec.download, ' downloads to date.')
                                end
                          end;
            utility_mode: st := st + 'U';
            sysop_mode  : st := st + 'S'
          end;
          if time_left <= 0
            then
              begin
                writeln(USR, BEL, BEL, BEL, 'Access time expired.  Please call back tomorrow.');
                remote_online := FALSE
              end
          else if time_left <= 2
                 then writeln(USR, BEL, 'Less than 2 minutes of access time left.  Please finish up.');
          writeln(USR);
          putstat(user_rec.fn + ' ' + user_rec.ln + '  ' + user_rec.ad +
            '  Access: ' + intstr(user_rec.access, 1) + '  On: ' +
            intstr(time_on, 1) + '  Heap: ' + intstr(MaxAvail, 1));
          ch := select(st, rep_msg[mode]);
          if op_chat
            then OK := chat
            else
              case mode of
                message_mode:
                  case ch of
                    'C': mesg_area_change('');
                    'E': mesg_enter(FALSE);
                    'F': mode := files_mode;
                    'G': in_use := FALSE;
                    'K': mesg_kill;
                    'Q': mesg_quick_scan;
                    'R': mesg_read;
                    'S': mesg_summary;
                    'U': mode := utility_mode;
                    'X': if (user_rec.access = 255) or (not remote_copy)
                           then mode := sysop_mode;
                    'I', 'O', '1'..'9': list(ch);
                    '?': list('M')
                  end;
                files_mode:
                  case ch of
                    'C': begin
                           if in_library
                             then library;
                           file_area_change('')
                         end;
                    'D': directory;
                    'F': toggle_st_switch;
                    'G': in_use := FALSE;
                    'L': library;
                    'M': mode := message_mode;
                    'N': newin_list;
                    'R': RecvXmodem;
                    'S': SendXmodem;
                    'T': SendText;
                    'U': mode := utility_mode;
                    'X': if (user_rec.access = 255) or (not remote_copy)
                           then mode := sysop_mode;
                    '?': list('F')
                  end;
                utility_mode:
                  case ch of
                    'A': alter_user_params;
                    'C': if chat
                           then mesg_enter(TRUE);
                    'F': mode := files_mode;
                    'G': in_use := FALSE;
                    'M': mode := message_mode;
                    'S': display_stats;
                    'T': display_time;
                    'U': display_users;
                    'X': if (user_rec.access = 255) or (not remote_copy)
                           then mode := sysop_mode;
                    '?': list('U')
                  end;
                sysop_mode:
                  case ch of
                    'A': toggle_audit;
                    'C': area_assign := not area_assign;
                    'D': delete_user;
                    'E': edit_user;
                    'F': mode := files_mode;
                    'G': in_use := FALSE;
                    'I': rebuild_index;
                    'K': begin
                           krunch_messages;
                           mesg_area_change(AreaReq)
                         end;
                    'L': print_log;
                    'M': mode := message_mode;
                    'N': process_newin;
                    'O': macro_setup;
                    'P': purge_user;
                    'R': print_messages;
                    'S': sys_dir;
                    'T': toggle_printer;
                    'U': mode := utility_mode;
                    'V': validate_user;
                    '?': list('X')
                  end
              end
        end;
      if in_library
        then library;
      if audit_on
        then toggle_audit;
      if user_rec.fn <> 'SYSOP'
        then if ask('Do you have a message for the sysop')
               then mesg_enter(TRUE);
      wrapup;
      setup;                                { Re-set system }
      wait_for_user
    end;
  system_de_init
end.
