/***************************************************************************/
/* SkyHatch.spot   ©1993 Stu Churchill   2:250/107.97@fidonet              */
/*                                                                         */
/* $VER: SkyHatch.spot 1.80 (7.9.93)                                       */
/*                                                                         */
/* This script will open SkyTick on Spot's public screen, then, after you  */
/* have hatched your files as required, it will post a File Arrival        */
/* Announcement message in the appropriate area. Please consult            */
/* SkyHatch.doc for more detailed information.                             */
/***************************************************************************/

options results

/***************************************************************************/
/* First we make sure that we can access the libraries we need             */
/***************************************************************************/

if ~show(l, 'rexxsupport.library') then do
  if ~addlib('rexxsupport.library', 0, -30) then do
    say 'Please install the rexxsupport.library in your libs: directory'
  end
end

/***************************************************************************/
/* Set up the system defaults                                              */
/***************************************************************************/

NL        = '0a'x
temp_file = 'T:2_250_107.TXT'
from_name = 'Stu Churchill'
to_name   = 'All'
subj_line = 'File Arrival Announcement'
echo_name = 'FILE_ANNOUNCE'
spot_path = 'Workbench:WBStartup/Spot'
psx_path  = 'Workbench:WBStartup/PSX'
tick_path = 'D:SkyTick'

/***************************************************************************/
/* First we open up SkyTick in HATCH mode on Spot's screen                 */
/***************************************************************************/

address command psx_path||' MAKEDEFAULT SPOT SHANGHAI'

call close('STDOUT')               /* Divert output to our own window */
call close('STDIN')
call open('window','CON:0/192//200//SCREEN SPOT')
call pragma('*','window')
call open('STDIN','*')
call open('STDOUT','*')

address command
tick_path' -CMAIL:Configs/Tick_Out/ HATCH'  /* Insert here Tick.cfg path */
psx_path' MAKEDEFAULT Workbench NOSHANGHAI' /* Reset default public screen */

call delay(3 * 50)                 /* A small delay for neatness */
call close('window')               /* before we close our window... */
call close('STDOUT')
call close('STDIN')
call pragma('*')
call open('STDIN','*')             /* ...and reset the default STDIN & */
call open('STDOUT','*')            /* STDOUT paths */

if exists(temp_file) then do       /* If we have hatched a file in an area */
  call writemsg(temp_file)         /* specified in Tick.cfg then this file */
end                                /* will exist */

exit


/***************************************************************************/
/* Write a file announcement message in the specified area                 */
/***************************************************************************/

writemsg:
  parse arg filename
  if ~show('ports','SPOT') then do
    address command spot_path
    'WaitForPort SPOT'
    if rc = 5 then do
      exit                      /* Exit if we couldn't start SPOT at all */
    end
    quit = yes                  /* Marker to close SPOT after finishing */
  end
  address 'SPOT'
  'isiconified'
  if rc = 0 then do
    icon = yes                  /* Marker to re-iconify after finishing */
    'uniconify'
  end
  'spot2front'
  'lockgui'
  'arealist'
  'gotoarea NAME 'echo_name
  if rc ~= 0 then do
    'requestnotify PROMPT "Could not find area'||NL||echo_name'"'
    exit
  end
  'messagelist'
  'write TO "'to_name'" FROM "'from_name'" SUBJECT "'subj_line'" FILE 'filename' NOEDIT NOGUI NOSIG'
  'arealist'
  'unlockgui'
  if icon = yes then do
    'iconify NOREQ'
  end
  if quit = yes then do
    'quitspot NOREQ'
  end
  call delete(temp_file)
  return
