%begin;                                  !TELL program.  A. Culloch
   %option "Nostack,Noopen,Upper"
   %include "Sysinc:command.inc"
   %routinespec stop
   %conststring(3) TTY dev = "T:"
   %record %format parm fm (%shortinteger dsno,dact,ssno,sact, %c
                           %integer p1,p2,p3,p4,p5,p6)
   %const %integer locate process = 5
   %const %integer process info = 14
   %const %integer pack filename = 17
   %const %integer unpack filename = 18
   %const %integer to director = 20;     !svc#
   %const %integer to accnt = 36;         !pass message to accountant process
   %const %integer status = 18
   %const %integer become = 27;          !dact
   %const %integer input ended = 9;      !event #
   %externalpredicatespec Exists(%string(31) File)
   !%option "NOstack,NOopen,Upper"
   %record(parm fm) P, Q
   %string(63) in1, out1
   %string(63)%name parm
   %external %string(17) %spec command prompt
   command prompt = "Command:";          !save confusing already BECOMEd users
   parm == Command_parameter
   %string(63) subj
   %integer j,c
   subj = ""
   %integer exclam = 0
   %for j = length(parm),-1,1 %cycle
      c = char no (parm,j)
      %if c = ')' %or c = ']' %or c = '}' %start
         subj = sub string (parm,1,j-1)
         j = j + 1 %until j > length(parm) %or char no (parm,j) > ' '
         parm = sub string (parm,j,length(parm))
         %exit
      %finish
   %repeat
   %if parm # "" %and char no (parm,length(parm)) = '!' %start
      length (parm) = length (parm) - 1
      exclam = 1
   %finish
   %if parm -> in1 . ("/") . out1 %start
   %finish %else in1 = "" %and out1 = parm
   P_p1 = 0;  P_p2 = x'D417A';  P_p3 = x'1BE81D81';  P_p6 = 0
   P_dact = BECOME;  SVC (to director,P)
   %if P_p6 # 0 %start
      print string ("TELL fails -- " . string(addr(P_p1)));  newline
      stop
   %finish
   %if out1 = "" %start
      print string ("TELL file / user")
      newline
      stop
   %finish
   length (out1) = length (out1) - 1 %if char no (out1,length(out1)) = ':'
   string (addr(P_sact)) = out1 . ":"
   SVC (pack filename,P)
   %if P_p2 < 0 %or P_p1 # 0 %or P_p4 & x'FFFF' # 0 %start
      print string ("*Invalid username - " . out1)
      newline
      stop
   %finish
   %if exclam # 0 %start
      %if length (subj) > 19 %start;   ! > 1 message
         length (subj) = 19
         print string ("Message truncated to '".subj."'
");   %finish
      SVC (locate process,P);          !POWNER => DSNO
      P_p6 = P_p1;  string (addr(P_p1)) = subj
      SVC (to accnt,P);                !relay message -> console
      stop
   %finish
   %if exists (out1) %start
      open input (1,out1)
   %else
      open input (1,"Null:")
   %finish
   select output (0)
   in1 = TTY dev %if in1 = ""
   %if in1 = TTY dev %start
      print string ("Enter message.  Type CTRL/D to stop")
      newline
   %finish
   open output (1,out1)
   select output (1)
   !append new text to file
   select input (1)
   %begin
      %on input ended %start
         %return
      %finish
      print symbol ('*')
      skip symbol %if next symbol = '*'
      %cycle
         print symbol (next symbol)
         skip symbol
      %repeat
   %end
   P_p1 = 0;  SVC (process info,P)
   P_p1 = 0;  P_p3 = 0;  P_p4 = 0;  SVC (unpack filename,P)
   print string ("From ")
   print string (string(addr(P_sact)))
   string (addr(Q_p1)) = "mail from " . string (addr(P_sact))
   length(string(addr(Q_p1))) = length(string(addr(Q_p1))) - 1
   space;  print string (date);  space;  print string (time);  space
   print string (" Subject:" . subj) %if subj # ""
   newline
   prompt ("")
   open input (1,in1)
   select input (1)
   %begin
      %integer ch
      %on input ended %start; %return; %finish
      %cycle
         read symbol (ch)
         %if NL # ch < ' ' %then print symbol ('?') %else print symbol (ch)
      %repeat
   %end
   print symbol (0);   !invisible frig seps messages
   close input
   close output
   string (addr(P_sact)) = out1 . ":";   !dest user
   SVC (pack filename,P)
   SVC (locate process,P)
   Q_p6 = P_p1;                          !dest service no
   SVC (to accnt,Q) %if P_p1 > 0;       !relay message if dest logged on
   !Back with P_p1 < 0 => no accountant there
   !If he was there, he sent a notify to "TO"
   stop
   %routine stop
      P_dact = become;  P_p2 = 0;  P_p6 = 0
      SVC (to director,P)
      %stop
   %end
%end %of %program
