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

  1. /*
  2. **  A simple beginning of a toy terminal using FIFO and sercli.
  3. **
  4. **  The idea was simple, and simply executed:
  5. **    Open a local NewCON: window for getting LOCAL user input
  6. **    Open a log file to indicate what happened during the execution
  7. **    until the user quits
  8. **        get a block of text from the FIFO (currently up to 4k --
  9. **        generally, however much is out there)
  10. **
  11. **        Log the text with a trailing FormFeed character so that it can
  12. **        be parsed later (bad choice, since FormFeeds may often be used
  13. **        by BBSses to clear screens).
  14. **
  15. **        Prompt the user for a response.  The response must begin with a
  16. **        `quit (', `continue (', or `respond (' string (case
  17. **        INsensitive).  Other than that, the command can be anything; a
  18. **        `CMD_' string is directly concatenated to the front of the user
  19. **        response, and then the whole is passed through the INTERPRET
  20. **        instruction -- thus the response can effectively be a whole
  21. **        ARexx program on a line.
  22. **        NOTE: The _remote_'s text is available through the variable
  23. **        TEXT whenever you are prompted for a response; you should
  24. **        be able to construct a `response command' that uses parts
  25. **        of the BBS information (e.g., when doing messages, you
  26. **        would want to respond by sending the message to a message
  27. **        file).
  28. **
  29. **        The user's response is also logged, and is also terminated with
  30. **        a formfeed.
  31. **
  32. **  Thus, at the end, one has a log file describing all of the `remote
  33. **  events', and all of the `local responses'.  It should be
  34. **  straightforward to use this information to generate a script for a
  35. **  given BBS.
  36. **
  37. **  Arbitrary additional commands may be added.
  38. **
  39. **  One thing I was planning on doing was to arrange for timeouts to be
  40. **  observed when reading serial input; thus one could do serial input,
  41. **  spewing long, multi-screen messages to a temporary file, and ONLY try
  42. **  to make a `decision' when the data stopped flowing for more than a
  43. **  couple of seconds.    This could be done by beefing up sercli a lot, or
  44. **  possibly by simply recoding for another terminal, such as VLT.  I was
  45. **  planning on doing it from ARexx by running a seperate ARexx script to
  46. **  do input, and another to provide 1-second `ticks', then monitor a
  47. **  message port to which each would send data; if <N> consecutive ticks
  48. **  come in with no intervening data, we do a timeout event; if data comes
  49. **  in, we zero the tick count & process the data.  (In fact, I've done
  50. **  something similar elsewhere -- it _is_ a little hairy, but it still has
  51. **  a certain appeal...)
  52. **
  53. **  Rather than using a FormFeed to terminate each section of input, I
  54. **  would suggest prefixing the section with a length, or creating an
  55. **  independant index file.
  56. **
  57. **  NOTE:
  58. **    HARD_CODED_MODEM_COMMAND is sent when this script starts up.
  59. **    Originally, I had selected a guinea pig BBS and made dialing it the
  60. **    first thing the script did.
  61. **
  62. **  NOTE ALSO:
  63. **    The NewCON: window does NOT exist under v2.0.  However, using CON:
  64. **    would throw away command line history & most command line editing
  65. **    under v1.3.  Since I having used this command in a long time & only
  66. **    upgraded from v1.3 recently, I have not changed this.
  67. **
  68. **  NOTE FURTHER:
  69. **    There is no ^C-^F handling installed; be careful, or add some...
  70. **    (I don't think the CON: window sends BREAKs when in RAW mode; since
  71. **    FIFO controls RAW mode for sercli, there's not much I can do about
  72. **    it...)
  73. **
  74. **  NOTE LASTLY:
  75. **    This program ASSUMES it is talking to a sercli with an ARexx port
  76. **    named `rkr'; the sercli window title bar is used to post certain
  77. **    messages (mostly used for isolating problems, as I recall).
  78. **
  79. */
  80.     options results
  81.     address 'rkr' "window size: 640 10"
  82.     eol = '0d'x
  83.  
  84.     /* HARD_CODED_MODEM_COMMAND = 'ATD 469 4401'eol */
  85.     HARD_CODED_MODEM_COMMAND = 'ATZ'eol
  86.  
  87.     if ~open( log, "mail.log", 'a' ) then do
  88.     exit( 0 )
  89.     end
  90.     x = title( 'log file open.' )
  91.  
  92.     if ~open( usr, "newcon:0/0/640/100/userinput", r ) then do
  93.     exit( 0 )
  94.     end
  95.     x = title( 'user input open...' )
  96.  
  97.     address command "set_raw"
  98.     x = title( 'DOS RAW mode on.' )
  99.  
  100.     x = writech( stdout, HARD_CODED_MODEM_COMMAND )
  101.     x = title( 'Dialing' )
  102.  
  103.     valid_cmd. = 0
  104.     valid_cmd.quit = 1
  105.     valid_cmd.continue = 1
  106.     valid_cmd.respond = 1
  107.  
  108.     x = title( 'main loop...' )
  109.     done = 0
  110.     do while ~done
  111.     text = readch( stdin, 4096 )
  112.     x = writech( log, text )
  113.     x = writech( log, '0c'x )
  114.     x = writech( usr, '{'text'} ' )
  115.     cmd = ''
  116.     do while ~valid_cmd.cmd
  117.         x = writeln( usr, cmd 'Response?' )
  118.         rsp = readln( usr )
  119.         parse value rsp with cmd '('
  120.         cmd = upper( cmd )
  121.         end
  122.     x = writech( log, rsp'0c'x )
  123.     cmd = 'cmd_'rsp
  124.     interpret( 'x =' cmd )
  125.     end
  126.  
  127.     delay( 5 )
  128.  
  129. /***    address command "set_con"   ***/    /*** not needed... ***/
  130.  
  131.     exit( 0 )
  132.  
  133.  
  134. title:
  135.     parse arg new_title
  136.     address 'rkr' 'window title:' new_title
  137.     return result
  138.  
  139.  
  140. cmd_quit:
  141.     done = 1
  142.     writeln( usr, "Quiting..." )
  143.     return 0
  144.  
  145.  
  146. cmd_continue:
  147.     writeln( usr, "Continuing..." )
  148.     return 0
  149.  
  150.  
  151. cmd_respond:
  152.     parse arg text
  153.     return writech( stdout, text )
  154.