home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 29 Fixes_o / 29-Fixes_o.zip / tcpcsd2.zip / BASECSD2.EXE / BIN / AUTOANS.CMD < prev    next >
OS/2 REXX Batch file  |  1993-07-12  |  8KB  |  197 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                OS/2 2.0 SLIP Driver for IBM TCP/IP version 2.0           */
  4. /*                                                                          */
  5. /*                                AUTOANS.CMD                               */
  6. /*                                                                          */
  7. /*            ..................................................            */
  8. /*                                                                          */
  9. /* Sample attachment script for putting the modem in auto answer mode for   */
  10. /* others to dial into this machine.  This script should be specified using */
  11. /* the "attachcmd" and "attachparm" elements in the SLIP.CFG file.          */
  12. /* For example:                                                             */
  13. /*                                                                          */
  14. /*              interface sl0 {                                             */
  15. /*                 attachcmd  = autoans                                     */
  16. /*              }                                                           */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /* When the script runs, it is automatically passed the interface name for  */
  20. /* the interface it is running on as the first argument, and the user       */
  21. /* arguments (from SLIP.CFG) as the second argument.                        */
  22. /*                                                                          */
  23. /*--------------------------------------------------------------------------*/
  24.  
  25. parse arg interface , comport baud
  26. /* Setup modem for autoanswer mode */
  27. /* check for input arg (slip interface for now) */
  28.  
  29. /* Set some definitions for easier COM strings */
  30. cr='0d'x
  31. crlf='0d0a'x
  32. reset='ATZ'       /* Reset command to send to modem */
  33. anscmd='ATS0=2S95=45S7=30'   /* Pickup after x ring(s) */
  34.  
  35. /* check input args and take default if not specified in SLIP.CFG */
  36. if interface='' | interface='*' then do
  37.    call lineout , ' AUTOANS: INTERFACE not specified.  Default SL0 '
  38.    interface='sl0'
  39.   end
  40.  
  41. if comport= '' | comport='*' then do
  42.    call lineout , ' AUTOANS: COM Port was not specified.  Default COM1 '
  43.    comport='COM1'
  44.   end
  45.  
  46. if baud='' | baud='*' then do
  47.    call lineout , ' AUTOANS: BAUD was not specified.  Default 1200 '
  48.    baud='1200'
  49.   end
  50.  
  51. /* Setup TCPIP info for this machine */
  52. call lineout , ' AUTOANS: Setting up TCPIP info for this machine ...'
  53.  
  54. 'arp -f'
  55. 'ifconfig ' interface' 222.222.222.10 222.222.222.20 netmask 255.255.255.0'
  56. 'route -fh add default 222.222.222.20 1'
  57.  
  58. /* Setup COM Port */
  59. call lineout , ' AUTOANS: COM Port settings: mode 'comport baud',n,8,1'
  60. 'mode 'comport baud',n,8,1,BUFFER=ON'
  61.  
  62. /*--------------------------------------------------------------------------*/
  63.  
  64.  
  65. /*--------------------------------------------------------------------------*/
  66. /*                   Initialization and Main Script Code                    */
  67. /*--------------------------------------------------------------------------*/
  68.  
  69.  
  70. /* Flush any stuff left over from previous COM activity */
  71. call flush_receive
  72.  
  73. /* Reset & put modem in Auto Answer mode */
  74. call send reset || cr
  75. call waitfor 'OK'
  76. call send anscmd || cr
  77. call waitfor 'OK' ; call flush_receive 'echo'
  78.  
  79. /* Setup All done, returning control to SLIP */
  80. exit 0
  81.  
  82.  
  83. /*--------------------------------------------------------------------------*/
  84. /*                            send ( sendstring)                            */
  85. /*..........................................................................*/
  86. /*                                                                          */
  87. /* Routine to send a character string off to the modem.                     */
  88. /*                                                                          */
  89. /*--------------------------------------------------------------------------*/
  90.  
  91. send:
  92.  
  93.    parse arg sendstring
  94.    call slip_com_output interface , sendstring
  95.  
  96.    return
  97.  
  98. /*--------------------------------------------------------------------------*/
  99. /*                    waitfor ( waitstring , [timeout] )                    */
  100. /*..........................................................................*/
  101. /*                                                                          */
  102. /* Waits for the supplied string to show up in the COM input.  All input    */
  103. /* from the time this function is called until the string shows up in the   */
  104. /* input is accumulated in the "waitfor_buffer" variable.                   */
  105. /*                                                                          */
  106. /* If timeout is specified, it says how long to wait if data stops showing  */
  107. /* up on the COM port.                                                      */
  108. /*                                                                          */
  109. /*--------------------------------------------------------------------------*/
  110.  
  111. waitfor:
  112.  
  113.    parse arg waitstring , timeout
  114.  
  115.    waitfor_buffer = '' ; done = 0 ; curpos = 1
  116.  
  117.    if (remain_buffer = 'REMAIN_BUFFER') then do
  118.       remain_buffer = ''
  119.    end
  120.  
  121.    do while done = 0
  122.       if (remain_buffer \= '') then do
  123.          line = remain_buffer
  124.          remain_buffer = ''
  125.       end
  126.       else do
  127.          line = slip_com_input(interface)
  128.       end
  129.       waitfor_buffer = waitfor_buffer || line
  130.       index = pos(waitstring,waitfor_buffer)
  131.       if (index > 0) then do
  132.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  133.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  134.          done = 1
  135.       end
  136.       call charout , substr(waitfor_buffer,curpos)
  137.       curpos = length(waitfor_buffer)+1
  138.     end
  139.  
  140.   return
  141.  
  142.  
  143. /*--------------------------------------------------------------------------*/
  144. /*                               readpass ()                                */
  145. /*..........................................................................*/
  146. /*                                                                          */
  147. /* Routine used to read a password from the user without echoing the        */
  148. /* password to the screen.                                                  */
  149. /*                                                                          */
  150. /*--------------------------------------------------------------------------*/
  151.  
  152. readpass:
  153.  
  154.   answer = ''
  155.   do until key = cr
  156.     key = slip_getch()
  157.     if key \= cr then do
  158.       answer = answer || key
  159.     end
  160.   end
  161.   say ''
  162.   return answer
  163.  
  164.  
  165. /*--------------------------------------------------------------------------*/
  166. /*                             flush_receive ()                             */
  167. /*..........................................................................*/
  168. /*                                                                          */
  169. /* Routine to flush any pending characters to be read from the COM port.    */
  170. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  171. /* point it returns.                                                        */
  172. /*                                                                          */
  173. /* The optional echo argument, if 1, says to echo flushed information.      */
  174. /*                                                                          */
  175. /*--------------------------------------------------------------------------*/
  176.  
  177. flush_receive:
  178.  
  179.    parse arg echo
  180.  
  181.    /* If echoing the flush - take care of waitfor remaining buffer */
  182.    if (echo \= '') & (length(remain_buffer) > 0) then do
  183.       call charout , remain_buffer
  184.       remain_buffer = ''
  185.    end
  186.  
  187.    /* Eat anything left in the modem or COM buffers */
  188.    /* Stop when nothing new appears for 100ms.      */
  189.  
  190.    do until line = ''
  191.      line = slip_com_input(interface,,100)
  192.      if echo \= '' then
  193.         call charout , line
  194.    end
  195.  
  196.    return
  197.