/* $VER: Terminus 2.0 - dialer.scp (03.07.93) */

/*
**    This is a simple script to manage dialing via scripts.
** It mimicks a subset of what the dialer is doing inside
** Terminus and is meant to show how to use WHEN commands, 
** but could be expanded for special purpose connection
** requirements.
**
** Global variable usage:
**
** Call with:
**    
**    d$ = phone number
**    n$ = name
**    i  = # of dialing attempts before exiting
**    t  = dial attempt timeout value
**    r  = redial delay timeout value
**
** Used:
**
**    a$ = dial prefix
**    p$ = dial postfix
**    j  = counter
**
** Exit:
**
**    k  = 1 for connection, 0 busy or exceeded dial attempts.
**
*/

dial:
   a$ = "atdt"
   p$ = "^m"

   send "^m"
   wait "OK"
   cls
   when all
   when 1 "RING" goto ring
   when 2 "BUSY" goto busy
   when 3 "CONNECT" goto connect

   for j = 1 to i
      print local "Dialing: "; n$; ", attempt - "; j
      send a$
      send d$
      send p$
      wait t
      send p$
      print local "Waiting..."
      wait r
   next
   /* fall thru */

busy:
   k = 0
   goto end_dial

connect:
   k = 1
   /* fall thru */

end_dial:
   end
