! New 1976-spec filestore
! The main program which initialises everything and
! starts up all the processes, before diving into the
! scheduler, from whence it never (we hope!) returns.

%constinteger default encrypted password = 16_212AF09E;  ! The system password

%include "CONFIG.INC"
%include "COMMON"
%include "UTILITY.INC"

%externalstring(255)%fnspec unpack VAX date(%short date)

%include "I:UTIL.INC"

%recordformat frig fm(%record(common fm)%name common)
%externalrecord(frig fm)%spec common frig
! These are needed because %external %names don't work.

%externalroutinespec init common
%externalroutinespec start processes
%externalroutinespec schedule

%externalroutinespec set VAX date(%string(255) date)
%externalstring(31)%fnspec VAX date

%externalroutinespec upper case(%string(*)%name s)

%begin
   %record(common fm) common area
   %string(255) d, t
   %integer i
   %short xd, xt
      open input(1, ":T");  select input(1)
      ! We may have been started up in a command file.
      set terminal mode(no page)
      d = VAX date
      %if d = "" %start
         ! VAX not responding.  Ask for the date on the console.
try again:
         printstring("Enter date in the form DD-MMM-YYYY")
         newline
         read string(d)
         upper case(d)
         printstring("Enter time in the form HH.MM")
         newline
         read string(t)
         d = d . "  " . t
      %else
         ! Fiddle the time part's format
         length(d) = 18;  charno(d, 16) = '.'
      %finish
      -> invalid %if length(d) # 18
      charno(d, 1) = '0' %if charno(d, 1) = ' ';  ! Leading space allowed
      set VAX date(d)
      time stamp(xd, xt)
      %unless unpack VAX date(xd) . "  " . unpack time(xt) = d %start
invalid: printstring("Invalid date or time: ");  printstring(d);        newline
         printstring("Should be, for example, 01-JUN-1984 and 12.45");  newline
         -> try again
      %finish
      common area = 0;  ! zap everything
      common area_system pass = default encrypted password
      common frig_common == common area
      init common;      ! Unfortunately main programs and %externals don't mix...
      start processes;  ! Start off all the processes.
      schedule;         ! Dive off into the scheduler (shoudn't ever come back).
      printstring("*** Returned from scheduler ***");  newline
%end %of %program
