! Vax-style GONE utility. Originated by MDP and AJS but rewritten by JHB 8/84
! to use standard utilities. now works again.
! modified 5/2/85 by DAK to get rid of last remains of WHODAT stuff

%include "inc:atdecs.imp"
%include "inc:fs.imp"
%include "inc:util.imp"
%include "inc:fsutil.imp"
%recordformat sf(%integer ptr,lim,server,extra)
%ownstring(5)block

%begin; ! Gone

%string (255) Where, Whole Line
%string (127) gone file = ":GONE.AWAY"
%string (6)   User Name
%integer dump

%routine Format (%string (255) Line)
   %string (80) This

   %cycle
      %if Length (Line) > 80 %start
         This = Sub String (Line, 1, 80)
         Line = Sub String (Line, 81, Length (Line))
      %else
         This = Line
         Line = ""
      %finish
      Print String (This)
      New Line %if Line # ""
   %repeat %until Line = ""
%end

%routine move(%integer bytes, %bytename from, to)                 {*s}
   !Move BYTES bytes from FROM to TO. Pinched from IE.                      {*c}
   !If addr(FROM) < addr(TO) do the move from the top down to allow overlap {*c}
   %return %if Bytes = 0 %or  From == To
   %if Addr (To) < Addr (From) %start
      *Subq.l #1, d0
   f loop:
      *move.b (a0)+, (a1)+
      *dbra   d0, f loop
   %else
      *add.l  d0, a0
      *add.l  d0, a1
      *subq.l #1, d0
   b loop:
      *move.b -(a0), -(a1)
      *dbra   d0, b loop
   %finish
%end

%routine do command(%string (255) verb, params, aux data)
   !Execute the supplied command as if typed from the console.

   move(length(verb), charno(verb,1), byteinteger(lend)); lend = lend + length(verb)
   %if params # "" %start
      byteinteger(lend) = ' '; lend = lend + 1
      move(length(params), charno(params, 1), byteinteger(lend)); lend = lend + length(params)
   %finish
   byteinteger(lend) = nl; lend = lend + 1
   move(length(aux data), charno(aux data, 1), byteinteger(lend)); lend = lend + length(aux data)
%end

%routine Normal Message (%string (255) Where)

   Whole Line = Where." at ".Time."  ".Date

   Open Output (1,gone file)
   Select Output (1)

   Format ("went ".Whole Line)
   New Line

   Close Output
   Select Output (0)
%end

%routine Cookie Message

   %own %string (5) block
   %integer start,length,choice,ch

  connect file ("Useful:Nor.Foi",0, start, length)
  choice = rem (cputime,length>>2)
  choice = integer (start+choice<<2)

  Open Input (1,"Useful:Nor.For")
  Select Input (1)
  Set Input (choice)

  %cycle
     read symbol (ch)
     %exit %if ch = '%' %and next symbol = '%'
     print symbol (ch)
  %repeat

  Close Input
  Select Input (0)
%end

   Where = CLI Param
   Where = "away" %if Where = ""

   Dump = Fcomm ('J'<<8,"") ;!Set back to home directory
   User Name = Current Directory
   Gone File = User Name.Gone File

   Normal Message (Where)
   Cookie Message

   do command("L","","")
%end %of %program
