! Non-MSF version

%include "inc:util.imp"
%begin
   print line (date."  ".time)
%end %of %program

! MSF version

!Time of Day utility.  This version asks filestore 'B' for MSF time from its
!clock card.  See bottom of file for non-MSF version (e.g. Appleton Tower)

%option "-ass-check-diag"
%include "clock:msftime.inc"
{APM}%include "INC:UTIL.IMP"
!VAX!%include "imp_include:pam.inc"
!VAX!!** link with sys$library:ether/lib,imp_include:pam
%begin
%constant %integer full time    = 2_1000 0000 0000 0000 0000 0000 0000 0000,
                   compact time = 2_0100 0000 0000 0000 0000 0000 0000 0000,
                   raw time     = 2_0010 0000 0000 0000 0000 0000 0000 0000,
                   last update  = 2_0001 0000 0000 0000 0000 0000 0000 0000,
                   bootproc time= 2_0000 1000 0000 0000 0000 0000 0000 0000,
                   all of them  = 2_0000 0100 0000 0000 0000 0000 0000 0000
%record (msf fm) t ;!Time record
%string(31) server
%string(55) crap1, crap2
%integer flags

%routine printstring(%string(255)s)
%integer i,j
  %for i = 1,1,length(s) %cycle
    j = charno(s,i)
    printsymbol(j) %unless j>=128
  %repeat
%end

%integer %function htoi (%string(31) h)
  !** convert string of hex to an integer
  %integer i, j, k
  %result = 0 %if length(h) = 0
  j = 0
  %for i = 1,1,length(h) %cycle
    k = charno(h,i) - '0'
    k = k-7 %if k > 9
    j = j*16 + k
  %repeat
  %result = j
%end

server="15"
flags = 0
define param ("Server address",server,0)
define boolean params ("Full,Compact,Raw,Updated,Bootproc,All",flags,0)
process parameters (cliparam)
!** now got all parameter information

t = msf time (htoi(server))
flags=full time %if flags = 0
flags=flags!full time!compact time!last update!bootproc time %if flags&all of them # 0

%if t_state = 0 %start
  printstring (t_full time.SNL) %if flags&full time # 0

  %if flags&compact time # 0 %start
    %if flags&full time # 0 %and t_full time -> crap1.("  ").crap2 %then %c
      spaces(length(crap1)-8)
    printstring (t_compact time)
    %if t_current time_BST = 1 %then printstring(" BST") %c
                                  %else printstring(" GMT")
    printstring(" (compact format)")
    newline
  %finish

  %if flags&last update # 0 %start
    %if flags&full time # 0 %and t_full time -> crap1.("  ").crap2 %then %c
      spaces(length(crap1)-8)
    printsymbol('0') %if t_last updated_day of month < 10
    write (t_last updated_day of month,0)
    printsymbol('/')
    printsymbol('0') %if t_last updated_month < 10
    write (t_last updated_month,0)
    printsymbol('/')
    printsymbol('0') %if t_last updated_year < 10
    write (t_last updated_year,0)
    printstring("  ")
    printsymbol('0') %if t_last updated_hour < 10
    write (t_last updated_hour,0)
    printsymbol(':')
    printsymbol('0') %if t_last updated_minute < 10
    write (t_last updated_minute,0)
    printstring("       MSF updated") %if flags # last update
    newline
  %finish

  %if flags&raw time # 0 %start
    write (t_current time_BST,2);         write (t_current time_century,2)
    write (t_current time_year,2);        write (t_current time_month,2)
    write (t_current time_day of month,2);write (t_current time_day of week,2)
    write (t_current time_hour,2);        write (t_current time_minute,2)
    write (t_current time_second,2);      write (t_current time_hundred,2)
    newline
  %finish

  %if flags&bootproc time # 0 %start
    %if flags&full time # 0 %and t_full time -> crap1.("  ").crap2 %then %c
      spaces(length(crap1)-8)
    printstring (date."  ".time)
    printstring("       Boot processor time") %if flags # bootproc time
    newline
  %finish
%finish %else %start
  printstring ("Error")
  write(t_state,1)
  printstring (" - ".t_full time.snl)
%finish
  
%end %of %program


