! APM Find Utility
!
!Change : - Added FIND <username>,<username>,..... - martin 4/11/83
!           Added real user names                  - martin 9/12/83
!           Modified to run on new FS              - AJS 14/2/84
!           Added Checks for valid users &         - AJS 7/3/84
!                            valid machines
!

%begin

%include "inc:fs.imp"
%include "useful:whodat.inc"
%include "fmacs:clients.inc"
%include "inc:fsutil.imp"

%Constinteger VAX = 72

%record (User Fm) %array Users (1:Client Max)
%integer Number of Users

%predicate connect gone file (%string (6) whois)
   %on 9 %start
      %false
   %finish

   open input (1,whois.":GONE.AWAY")
   select input (1)
   %true
%end

%routine print gone message (%string (255) Line)
   %integer sym, Count = 150

   %on 9 %start
      %return
   %finish

   %cycle
      read symbol (sym)
      Count = Count - 1
      %exit %if Count = 0 %or Sym = Nl
      Line = Line . To String (Sym)
   %repeat %until Count = 0

   Format (Line)
   New Line
%end

%string (127) %fn print name (%string (7) whois)

   %integer index = Find Index (whois)

   %if Index > Max Fs Users %then %result = "*"
   %result = Fs Names (Index)." (".whois.") "
%end

%routine find one user (%string (6) whois)
%record (User Fm) %name Some One
%integer uno, logged on = 0
%string(63) loc,ename

  %for uno = 1,1,number of users %Cycle
      Some One == Users(uno)
      %If Some One _ User Name = whois %Start
          %If Some One_Location = VAX %Start
             loc = "on the VAX"
          %Else %If Some One_Location > ClientMax
             loc = "on an unknown station"
          %Else
             loc = whereabouts (Some One_Location)
          %Finish
          Printstring (printname(whois) .("is ").loc)
          newline
          Logged On = 1
      %finish
  %repeat

  %If Logged On = 0 %start
     ename = Print Name (Whois)
     %IF ename = "*" %Start
        printstring (whois." is a figment of your imagination");newline
     %Else
        %if connect gone file (whois) %start
           print gone message (ename)
        %finish %else %start
           Printstring (Print name (whois) . "is nowhere to be found")
           newline
        %finish
     %finish
  %finish

%end

!**********************************************************************
!****
!****    Start Of Proggy
!****

%string (127) line, whois
%integer index

   %on 9 %Start
      newline
      %Stop
   %Finish

   Get Unos From Fs (Users, Number of Users, Index)

   line = CLI param
   %if line = "" %start
      print string ("Find who ???")
      new line
      %stop
   %finish

   upper case (line)
   line = line.whois %while line -> line.(" ").whois

   index = 1
   %while index <= length (line) %cycle

      whois = ""
      %while index <= length (line) %and charno (line, index) # ',' %cycle
         whois = whois.to string (charno (line, index))
         index = index + 1
      %repeat
      index = index + 1 %if charno (line, index) = ','

      %if length (whois) > 6 %start
         print string ("Invalid user name ".whois)
         new line
      %finish %else %start
         find one user (whois) %unless whois = ""
      %finish
   %repeat

%endofprogram
