home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / utils / sercli.shr / sercli / example / refuse_callers / refuse_callers.rexx next >
Encoding:
OS/2 REXX Batch file  |  1993-06-16  |  4.6 KB  |  165 lines

  1. /*
  2. **  This is a simple program to
  3. **    Answer the phone
  4. **    send a `status.text' file out over the modem
  5. **
  6. **  All the while, it logs _every_ input line, along with a date-stamp for
  7. **  when the line of text came in.  As an IMHO desirable side-effect, the
  8. **  user can enter any arbitrary text after connecting, and it will be
  9. **  recorded, verbatim, in a log file.
  10. **
  11. **  Modem disconnects are neither observed nor generated by this program;
  12. **  what it does is monitor input for a RING string; if it finds one it
  13. **  emits an `ATA', then waits for UP TO 2 lines of input in order to
  14. **  locate a CONNECT; if that fails, it goes back to looking for RING
  15. **  lines.  When there is a user nominally conencted to it, it is _still_
  16. **  looking for `RING' lines.
  17. **
  18. **  It ASSUMES that STDIO is associated with the modem.  If run from a CLI
  19. **  or Shell, you should type RING and CONNECT strings for yourself.
  20. **
  21. **  I wrote this script for only one purpose:
  22. **    To answer the phone & announce the status of my BBS while I decided
  23. **    how to replace it.  (I wound up going back to Proteus, at least for
  24. **    a while.)
  25. **
  26. **  To exit, you must use the ARexx hi (Halt Interpreter) command; ^C-^F
  27. **  breaks should be difficult or impossible to generate.
  28. **
  29. **  There are no other special caveats.  If you use it with sercli & FIFO,
  30. **  then make sure you read the .log file once in a while & update the
  31. **  Status.text file as well.  My way of updating Status.text was to
  32. **  compress most events down to a single line as soon as a newer event was
  33. **  added; each event had a date associated with it.  Events were ordered
  34. **  from oldest to newest.  Old events that had been compressed to one line
  35. **  were occaisionally deleted or merged with others.  My last version of
  36. **  Status.text is included for giggles.
  37. **
  38. **  refuse_callers.rexx was run from a script very much like the sercli-run
  39. **  example for starting do_mail.rexx.
  40. **
  41. **  For pretty much the whole useful life span of this script, I ran it
  42. **  with an older version of sercli (v1.8).
  43. **
  44. */
  45.     /*
  46.     **    Custom handlers for these events; we don't want to let the user
  47.     **    break out of our script!
  48.     **
  49.     */
  50.     signal on break_c
  51.     signal on break_d
  52.     signal on break_e
  53.     signal on break_f
  54.  
  55.     /*
  56.     **    On `hi' (HALT), do a graceful exit.
  57.     **
  58.     */
  59.     signal on halt
  60.  
  61.     log = 'log'
  62.     log_file = 'refuse_callers.log'
  63.     if ~open( log, log_file, 'a' ) then
  64.     exit
  65.  
  66.     address command set_raw
  67.     status = 'Status.text'
  68.  
  69.     call log( 'Starting' )
  70. top:
  71.     do forever
  72.     call wait_line( 'RING' )
  73.     call writeln( stdout, 'ATA' || '0d'x )
  74.     connect_line = wait_line( 'CONNECT', 2 )
  75.     if 0 = pos( 'CONNECT', connect_line ) then
  76.         call log( 'ERROR, no connect!' )
  77.     else
  78.     do
  79.         call log( 'Connected with:' connect_line )
  80.         /*
  81.         **    call writeln( stdout, "(Login as `guest'.)" )
  82.         **    address command 'rlaunch * "logout"'
  83.         **
  84.         */
  85.         call send_file( status )
  86.         call writeln( stdout, 'GMT time/date (yyyymmdd hhmmss):' time_date( ) )
  87.     end
  88.     end
  89. exit
  90.  
  91. wait_line:
  92. parse arg wl_str, wl_max
  93.     if datatype( wl_max, 'n' ) then
  94.     wl_max = 'for 'wl_max
  95.     else
  96.     wl_max = ''
  97.  
  98.     wl_line = ''
  99.     interpret 'do' wl_max 'until 0 ~= pos( wl_str, wl_line ); wl_line = getln( ); call log( wl_line ); end'
  100. return wl_line
  101.  
  102. send_file:
  103. parse arg sf_fname
  104.     sf_text = ''
  105.     if ~open( 'sf_file', sf_fname, 'r' ) then
  106.     do
  107.     call log( 'Could not send file {'sf_fname'}' )
  108.     call writeln( stdout, 'Could not send file {'sf_fname'}' || '0d'x )
  109.     end
  110.     else
  111.     do
  112.     do while ~eof( 'sf_file' )
  113.         sf_line = readln( 'sf_file' )
  114.         sf_text = sf_text || '0a'x || sf_line
  115.         call writeln( stdout, sf_line'0d'x )
  116.     end
  117.     call close( 'sf_file' )
  118.     end
  119. return sf_text
  120.  
  121. getln:
  122.     g_ln = ''
  123.     g_done = 0
  124.     do until g_done
  125.     g_c = readch( stdin, 1 )
  126.     g_done = ( ( ('0a'x == g_c) | ('0d'x == g_c) ) ) & (g_last ~= g_c)
  127.     g_last = g_c
  128.     if ~g_done then
  129.         g_ln = g_ln || g_c
  130.     end
  131.     g_last = g_c
  132. return strip( g_ln, 'b', '0a0d'x )
  133.  
  134. log:
  135. parse arg l_str
  136. return writeln( log, time_date( ) ':' l_str )
  137.  
  138. time_date:
  139. parse value date( 's' ) time( ) with td_1 ':' td_2 ':' td_3
  140. return td_1 || td_2 || td_3
  141.  
  142.  
  143. break_c:
  144. break_d:
  145. break_e:
  146. break_f:
  147.     signal on break_c
  148.     signal on break_d
  149.     signal on break_e
  150.     signal on break_f
  151.  
  152.     call writeln( stdout, '0d'x )
  153.     call writeln( stdout, 'Sending a break is a naughty thing to do.' || '0d'x )
  154.     call writeln( stdout, '0d'x )
  155.  
  156.     signal top
  157.  
  158. halt:
  159.     call log( 'Ending' )
  160.     address command set_con
  161.     call writeln( stdout, '0d'x )
  162.     call writeln( stdout, 'Breaking refuse_callers.rexx script...' || '0d'x )
  163.     call writeln( stdout, '0d'x )
  164.     exit 0
  165.