/* SpotCLI */

address SPOT
options results

/* WINDSPEC='con:x-pos/y-pos/x-size/y-size/name/{options}/screen SPOT'
   where {options} consists of any combination of the following:
    /inactive      = will not activate the window once opened
    /nodepth       = no 'to back' gadget
    /nosize        = no change size gadget
    /nodrag        = window cannot be moved
    /noborder      = window has no border
    /close         = add a close gadget (nb: the close gadget will not work)
    /backdrop      = all other windows will appear in front
    /alt x-pos/y-pos/x-size/y-size = alternate size for shrink gadget

current setting for DBLPAL hi-res noflicker.  Alter to taste :-)

*/
windspecs="con:10/100/680/150/SpotCLI/noclose/alt 3/318/100/150/screen SPOT"
if ~show('p','SPOT') then exit

call close('STDOUT')
call close('STDIN')

if ~show('l','rexxsupport.library') then
  call addlib('rexxsupport.library',0,-30,0)

do forever
   if open('STDOUT',windspecs,'w') then do
      call pragma('*','STDOUT')

      if open('STDIN','*','r') then
         dummy=0
      else call close('STDOUT')
   end

   Say 'PSR Soft'
   Say ''
   hide=0
   lock=0

   do until hide=1
      found=0
      call writech('STDOUT','>')

      line=readln('STDIN')
      uline=upper(line)
      com=word(uline,1)

      if com='AREA' then do
         found=1
         if length(uline)>5 then do
            name=right(uline,length(uline)-5)
            'gotoarea' name
         end
         else do
            'requestarea TITLE "Area" ALL'
            name=result
            if ~(RC=5) then 'gotoarea' name
         end
      end
      if (com='U') | (com='UP') then do
         found=1
         num=word(uline,2)
         if ~datatype(num,'n') then num=1
         if num<1 then num=1
         'isarealist'
         if rc=0 then do c=1 to num
            'prevarea'
         end
         'ismessagelist'
         if rc=0 then do c=1 to num
            'prevmessage'
         end
      end
      if (com='D') | (com='DOWN') then do
         found=1
         num=word(uline,2)
         if ~datatype(num,'n') then num=1
         if num<1 then num=1
         'isarealist'
         if rc=0 then do c=1 to num
            'nextarea'
         end
         'ismessagelist'
         if rc=0 then do c=1 to num
            'nextmessage'
         end
      end
      if (com='LOCKGUI') & (~lock) then do
         found=1
         code=word(uline,2)
         if length(code)<1 then code='CODE'
         say code
         'lockgui'
         say '1b'x || 'c'
         lock=1
      end
      if com='UNLOCKGUI' then do
         found=1
         if code='CODE' then do
            'unlockgui'
            lock=0
         end
         if word(uline,2)=code then do
            'unlockgui'
            lock=0
         end
         if lock then say '  incorrect password'
      end
      if com='CLS' then do
      found=1
      say '1b'x || 'c'
      end
      if com='FREQ' then do
         found=1
         'filerequest'
      end
      if com='QUIT' | com='ENDCLI' | eof('STDIN') then do
         call close('STDOUT')
         call close('STDIN')
         exit
      end
      if com='HIDE' then do
         found=1
         rc=0
         hide=1
         do until rc=5
            call delay(50)
            'ismessages'
         end
      end
      if ~found then do
         "'"line"'"
      end
   end

   do until rc=5
      call delay(50)
      'ismessages'
   end
end
