home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / infomt16.zip / infomtch.cmd next >
OS/2 REXX Batch file  |  1995-09-24  |  37KB  |  734 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                              INFOMTCH.CMD                                */
  3. /*                                  v1.6                                    */
  4. /*                                                                          */
  5. /*                 Attachment script for Infomatch Internet                 */
  6. /*--------------------------------------------------------------------------*/
  7. /* Created from the sample ANNEX.CMD script distributed with IBM OS/2 Warp  */
  8. /* and it's Internet Access Kit.  Changes to original script made by Graham */
  9. /* TerMarsch.                                                               */
  10. /*--------------------------------------------------------------------------*/
  11. /* Portions of this script written by Harold Roussel, who can be reached at */
  12. /* roussel@physics.mcgill.ca.                                               */
  13. /*--------------------------------------------------------------------------*/
  14. /*                                                                          */
  15. /* Please refer to the INFOMTCH.DOC and the README file for information on  */
  16. /* the distribution of this script, its usage, and restrictions.            */
  17. /*                                                                          */
  18. /*--------------------------------------------------------------------------*/
  19. /* Graham is available for contract work involving OS/2.  He has been an    */
  20. /* avid user since 1992, and was involved in all of the beta programs since */
  21. /* then.  A registered OS/2 DAP member, Graham does most of his work in     */
  22. /* C/C++.  Being a starving student, Graham is almost always available for  */
  23. /* programming/installation/support work.  Contact him at 604-689-2073 or   */
  24. /* gtermars@infomatch.com for more information.                             */
  25. /*--------------------------------------------------------------------------*/
  26. /*                              DISCLAIMER                                  */
  27. /*                                                                          */
  28. /* You were waiting for this weren't you?  Well, it's a standard disclaimer;*/
  29. /* I've managed to get this working on my machine and have thus provided it */
  30. /* to others.  By use of this script you acknowledge that I am not          */
  31. /* responsible for any damages that may be incurred through it's use.  Yes, */
  32. /* I am available to answer your questions if you have a problem but I take */
  33. /* no responsibility for your actions.  You downloaded it, and if you use   */
  34. /* it you take full responsibility into your own hands.  If you do not      */
  35. /* agree with this then discontinue your use of this script.                */
  36. /*--------------------------------------------------------------------------*/
  37.  
  38.  
  39.  
  40. /*--------------------------------------------------------------------------*/
  41. /* Define and initialize all variables:                                     */
  42. /*                                                                          */
  43. /* cr                  - ASCII code for carriage return.                    */
  44. /* lf                  - ASCII code for line feed.                          */
  45. /* crlf                - ASCII code for carriage return and line feed.      */
  46. /* max_attempts        - Maximum number of redial attempts to make.  A      */
  47. /*                       value of zero means dial until connection is made. */
  48. /* curr_attempt        - Current dialing attempt number.                    */
  49. /* username            - User name to log in with.                          */
  50. /* password            - Password to log in with.                           */
  51. /* should_beep         - Should the bell be sounded upon connection or      */
  52. /*                       failure to connect?  A value of zero means NO, and */
  53. /*                       a value of one means YES.                          */
  54. /* should_autostart    - Should the LOGGEDIN.CMD file be run upon a         */
  55. /*                       successful connection?  A value of zero means NO,  */
  56. /*                       and a value of one means YES.                      */
  57. /* os2_address         - Dotted decimal notation for the IP address that    */
  58. /*                       this OS/2 machine will have when a connection has  */
  59. /*                       been made.                                         */
  60. /* how_many_numbers    - Number of phone numbers in the dialing list.       */
  61. /* phone_number        - Array containing the dialing list of numbers.      */
  62. /*                                                                          */
  63. /*                                                                          */
  64. /*--------------------------------------------------------------------------*/
  65. cr = '0d'x
  66. lf = '0a'x
  67. crlf = '0d0a'x
  68. max_attempts = 0
  69. curr_attempt = 0
  70. username = ''
  71. password = ''
  72. should_beep = 1
  73. should_autostart = 1
  74. how_many_numbers = 6
  75. phone_number.0 = "421-3288"
  76. phone_number.1 = "421-3957"
  77. phone_number.2 = "421-3914"
  78. phone_number.3 = "421-3886"
  79. phone_number.4 = "421-0411"
  80. phone_number.5 = "421-3277"
  81.  
  82. /*--------------------------------------------------------------------------*/
  83. /* Parse the command line options.  Keep in mind that while parsing the     */
  84. /* arguments, if an error is found the program will abort; we will NOT end  */
  85. /* up back here with any error conditions to check.                         */
  86. /*--------------------------------------------------------------------------*/
  87. parse arg interface, arguments
  88. call parse_arguments arguments
  89.  
  90. /*--------------------------------------------------------------------------*/
  91. /* Load any of the RexxUtil functions that we might require later.          */
  92. /*--------------------------------------------------------------------------*/
  93. call RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
  94. call RxFuncAdd 'SysDropFuncs', 'RexxUtil', 'SysDropFuncs'
  95.  
  96. /*--------------------------------------------------------------------------*/
  97. /* Say hello to the user and provide author information.                    */
  98. /*--------------------------------------------------------------------------*/
  99. say ''
  100. say 'INFOMTCH - Infomatch Internet SLIP login interface, version 1.5'
  101. say 'Written by Graham TerMarsch, 604-689-2073, gtermars@infomatch.com'
  102. say 'Portions by Harold Roussel, roussel@physics.mcgill.ca'
  103.  
  104. /*--------------------------------------------------------------------------*/
  105. /* Prompt the user for any information that might have been missing from    */
  106. /* the command line.                                                        */
  107. /*--------------------------------------------------------------------------*/
  108. if (os2_address  = '') then do
  109.         call charout , 'Your IP address: '
  110.         parse pull os2_address
  111. end
  112.  
  113. if ( (username = '') | (username = '*') ) then do
  114.         call charout , 'User Name: '
  115.         parse pull username
  116. end
  117.  
  118. if ( (password = '') | (password = '*') ) then do
  119.         call charout , 'Password: '
  120.         password = readpass()
  121. end
  122.  
  123. /*--------------------------------------------------------------------------*/
  124. /* Flush any left over stuff from previous COM activity.                    */
  125. /*--------------------------------------------------------------------------*/
  126. call flush_receive
  127.  
  128. /*--------------------------------------------------------------------------*/
  129. /* Reset the modem to it's factory default settings.                        */
  130. /*--------------------------------------------------------------------------*/
  131. call send '+++'
  132. call send 'AT&F' || cr
  133. call waitfor 'OK', 5
  134. call flush_receive
  135.  
  136. if (RC = 1) then do
  137.         call lineout , 'Modem not resetting... Trying to reset.'
  138.         call send '+++'
  139.         call waitfor 'OK'
  140.         call send 'ATHZ' || cr
  141.         call waitfor 'OK', 3
  142. end
  143.  
  144. /*--------------------------------------------------------------------------*/
  145. /* Now we'll attempt to do the dialing.  We'll continue to dial until we    */
  146. /* get connected.                                                           */
  147. /*--------------------------------------------------------------------------*/
  148. which_number = 0                       /* Which number should I be dialing? */
  149. say ''
  150.  
  151. do while ( (max_attempts = 0) | (curr_attempt < max_attempts) )
  152.         curr_attempt = curr_attempt + 1
  153.  
  154.         /*------------------------------------------------------------------*/
  155.         /* Wait a bit to be polite to the rest of the system.               */
  156.         /*------------------------------------------------------------------*/
  157.         SysSleep( 1 )
  158.  
  159.         /*------------------------------------------------------------------*/
  160.         /* Hang up on any existing call.                                    */
  161.         /*------------------------------------------------------------------*/
  162.         call send '+++'
  163.         call send 'ATHZ' || cr
  164.         call waitfor 'OK', 3
  165.         call send 'ATM0' || cr
  166.         call waitfor 'OK', 3
  167.  
  168.         /*------------------------------------------------------------------*/
  169.         /* Dial the remote server.                                          */
  170.         /*------------------------------------------------------------------*/
  171.         say 'Now dialing ' || phone_number.which_number || '.'
  172.  
  173.         /*------------------------------------------------------------------*/
  174.         /* Choose the number to call and dial it.                           */
  175.         /*------------------------------------------------------------------*/
  176.         call send 'ATDT' || phone_number.which_number || cr
  177.         which_number = which_number + 1
  178.  
  179.         if (which_number = how_many_numbers) then
  180.                 which_number = 0
  181.  
  182.         /*------------------------------------------------------------------*/
  183.         /* Wait for either a connection or an error message.  The return    */
  184.         /* value will come back through the variable 'stringchosen'.        */
  185.         /*------------------------------------------------------------------*/
  186.         call waitfor3 'CONNECT', 'BUSY', 'NO CARRIER'
  187.         call flush_receive
  188.  
  189.         /*------------------------------------------------------------------*/
  190.         /* If we've successfully connected, get out of the while loop.      */
  191.         /* 'stringchosen' represents which string from the last call to     */
  192.         /* waitfor3 that was detected; a value of 1 means that we got a     */
  193.         /* 'CONNECT'.                                                       */
  194.         /*------------------------------------------------------------------*/
  195.     if (stringchosen = 1) then
  196.                 leave
  197.         else if (stringchosen = 2) then
  198.                 call charout , 'Busy.' || cr
  199.         else if (stringchosen = 3) then
  200.                 call charout , 'No carrier.' || cr
  201. end     /* end of 'do while...' */
  202.  
  203. /*--------------------------------------------------------------------------*/
  204. /* Check to see why we ended up out of the previous dialing loop.  Was it   */
  205. /* because we have a connection or because we ran out of dialing attempts.  */
  206. /*--------------------------------------------------------------------------*/
  207. if (stringchosen > 1) then do
  208.         /*------------------------------------------------------------------*/
  209.         /* Inform the user that we have reached the maximum number of       */
  210.         /* dialing attempts.                                                */
  211.         /*------------------------------------------------------------------*/
  212.         say 'Reached maximum dialing attempts.' || cr
  213.  
  214.         /*------------------------------------------------------------------*/
  215.         /* If we are supposed to sound a bell to let the user know that an  */
  216.         /* error occured, sound the bell.                                   */
  217.         /*------------------------------------------------------------------*/
  218.         if (should_beep = 1) then call failure_beep 1
  219.  
  220.         return_value = 1
  221. end
  222. else do
  223.         /*------------------------------------------------------------------*/
  224.         /* Now that we have a connection at the other end of the line, try  */
  225.         /* to do the login.  Wait for the standard strings, and then flush  */
  226.         /* everything else that we do not need (trailing spaces, etc.).     */
  227.         /*------------------------------------------------------------------*/
  228.         say 'Connected to Infomatch Internet, attempting login.' || cr
  229.         call waitfor 'login:'
  230.         call flush_receive
  231.         call send username || cr
  232.  
  233.         call waitfor 'Password:'
  234.         call flush_receive
  235.         call send password || cr
  236.  
  237.         /*------------------------------------------------------------------*/
  238.         /* Wait for the connection established notification from the server.*/
  239.         /*------------------------------------------------------------------*/
  240.         call waitfor 'starting slip login for'
  241.         call flush_receive
  242.  
  243.         /*------------------------------------------------------------------*/
  244.         /* Now we check to ensure that we've connected properly.  If so,    */
  245.         /* set the IP address and add the name server to our routing table. */
  246.         /* Otherwise, display an error message to the user.                 */
  247.         /*------------------------------------------------------------------*/
  248.         if RC = 0 then do
  249.                 'ifconfig sl0' os2_address '199.60.99.1 netmask 255.255.255.0 >nul'
  250.                 'route add default 199.60.99.1 1 >nul'
  251.                 say 'SLIP Connection Established!'
  252.  
  253.                 /*----------------------------------------------------------*/
  254.                 /* If we are supposed to sound a bell to let the user know  */
  255.                 /* that a successful connection has been made, sound the    */
  256.                 /* bell.                                                    */
  257.                 /*----------------------------------------------------------*/
  258.                 if (should_beep = 1) then call success_beep 3
  259.  
  260.                 /*----------------------------------------------------------*/
  261.                 /* If we are supposed to autostart any other applications,  */
  262.                 /* start the LOGGEDIN.CMD script file.                      */
  263.                 /*----------------------------------------------------------*/
  264.                 if (should_autostart = 1) then detach LOGGEDIN.CMD
  265.  
  266.                 return_value = 0
  267.         end
  268.         else do
  269.                 say 'ERROR:  NO Connection Established!'
  270.  
  271.                 /*----------------------------------------------------------*/
  272.                 /* If we are supposed to sound a bell to let the user know  */
  273.                 /* that an error occured, sound the bell.                   */
  274.                 /*----------------------------------------------------------*/
  275.                 if (should_beep = 1) then call failure_beep 1
  276.  
  277.                 return_value = 1
  278.         end
  279. end
  280.  
  281. /*--------------------------------------------------------------------------*/
  282. /* At this point, we are finished; we've either ran out of dial attempts,   */
  283. /* made a successful connection, or failed in a connection.  So, clean up   */
  284. /* any REXX functions that we loaded and exit the script.                   */
  285. /*--------------------------------------------------------------------------*/
  286. call SysDropFuncs
  287. exit return_value
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294. /*--------------------------------------------------------------------------*/
  295. /*                         success_beep ( numTimes )                        */
  296. /*..........................................................................*/
  297. /*                                                                          */
  298. /* Routine to beep several times to indicate a successful connection.       */
  299. /*                                                                          */
  300. /*--------------------------------------------------------------------------*/
  301. success_beep:
  302.         parse arg numTimes
  303.  
  304.         do while (numTimes > 0)
  305.                 call beep 580, 90
  306.                 call beep 650, 90
  307.                 call beep 800, 80
  308.                 numTimes = numTimes - 1
  309.         end
  310. return
  311.  
  312.  
  313. /*--------------------------------------------------------------------------*/
  314. /*                         failure_beep ( numTimes )                        */
  315. /*..........................................................................*/
  316. /*                                                                          */
  317. /* Routine to beep several times to indicate a failed connection.           */
  318. /*                                                                          */
  319. /*--------------------------------------------------------------------------*/
  320. failure_beep:
  321.         parse arg numTimes
  322.  
  323.         do while (numTimes > 0)
  324.                 call beep 600, 90
  325.                 call beep 500, 90
  326.                 call beep 300, 300
  327.                 numTimes = numTimes - 1
  328.         end
  329. return
  330.  
  331.  
  332. /*--------------------------------------------------------------------------*/
  333. /*                            send ( sendstring )                           */
  334. /*..........................................................................*/
  335. /*                                                                          */
  336. /* Routine to send a character string off to the modem.                     */
  337. /*                                                                          */
  338. /*--------------------------------------------------------------------------*/
  339. send:
  340.         parse arg sendstring
  341.         call slip_com_output interface , sendstring
  342. return
  343.  
  344.  
  345. /*--------------------------------------------------------------------------*/
  346. /*                       parse_arguments ( arguments )                      */
  347. /*..........................................................................*/
  348. /*                                                                          */
  349. /* Parses the command line arguments to this script file.  Any known        */
  350. /* arguments will set the appropriate variables in the program.  If we      */
  351. /* encounter an invalid argument or an argument without a value, display an */
  352. /* error message and abort the script completely.                           */
  353. /*                                                                          */
  354. /*--------------------------------------------------------------------------*/
  355. parse_arguments:
  356.         parse arg argument arg_value arguments
  357.  
  358.         /*------------------------------------------------------------------*/
  359.         /* If we have no argument, then simply return.  This is required as */
  360.         /* this routine is called recursively.                              */
  361.         /*------------------------------------------------------------------*/
  362.         if (argument = '') then return
  363.  
  364.         /*------------------------------------------------------------------*/
  365.         /* Translate the argument into upper case so it will be easeir to   */
  366.         /* parse.                                                           */
  367.         /*------------------------------------------------------------------*/
  368.         argument = translate( argument )
  369.  
  370.         /*------------------------------------------------------------------*/
  371.         /* Depending on which command line argument we have, set the        */
  372.         /* appropriate variable.  If the value given either doesn't exist   */
  373.         /* or is invalid, display an error message to the user and abort.   */
  374.         /*------------------------------------------------------------------*/
  375.         SELECT
  376.                 WHEN (argument = '-ATTEMPTS') then do
  377.                         /*--------------------------------------------------*/
  378.                         /* Check to see that we have a numeric value here.  */
  379.                         /* If not, display an error message and quit.       */
  380.                         /*--------------------------------------------------*/
  381.                         if (arg_value \= '') then do
  382.                                 if (datatype( arg_value ) = 'NUM') then do
  383.                                         max_attempts = arg_value
  384.                                 end
  385.                                 else do
  386.                                         say 'Attempts requires a numeric parameter.' || cr
  387.                                         exit 1
  388.                                 end
  389.                         end
  390.                         else do
  391.                                 say 'Attempts requires a parameter.' || cr
  392.                                 exit 1
  393.                         end
  394.                 end
  395.                 WHEN (argument = '-NAME') then do
  396.                         /*--------------------------------------------------*/
  397.                         /* Check to see that we have been given a username. */
  398.                         /* If not, display an error message and quit.       */
  399.                         /*--------------------------------------------------*/
  400.                         if (arg_value = '') then do
  401.                                 say 'Name requires a username parameter.' || cr
  402.                                 exit 1
  403.                         end
  404.                         else do
  405.                                 username = arg_value
  406.                         end
  407.                 end
  408.                 WHEN (argument = '-PASSWORD') then do
  409.                         /*--------------------------------------------------*/
  410.                         /* Check to seee that we have been given a password.*/
  411.                         /* If not, display an error message and quit.       */
  412.                         /*--------------------------------------------------*/
  413.                         if (arg_value = '') then do
  414.                                 say 'Password requires a password parameter.' || cr
  415.                                 exit 1
  416.                         end
  417.                         else do
  418.                                 password = arg_value
  419.                         end
  420.                 end
  421.                 WHEN (argument = '-BEEP') then do
  422.                         /*--------------------------------------------------*/
  423.                         /* Translate the argument value into uppercase.     */
  424.                         /*--------------------------------------------------*/
  425.                         arg_value = translate( arg_value )
  426.  
  427.                         /*--------------------------------------------------*/
  428.                         /* Check to see that the given parameter is either  */
  429.                         /* ON or OFF.  If not, display an error message and */
  430.                         /* quit.                                            */
  431.                         /*--------------------------------------------------*/
  432.                         if (arg_value = 'ON') then do
  433.                                 should_beep = 1
  434.                         end
  435.                         else do
  436.                                 if (arg_value = 'OFF') then do
  437.                                         should_beep = 0
  438.                                 end
  439.                                 else do
  440.                                         say 'Beep requires either ON or OFF as a parameter.' || cr
  441.                                         exit 1
  442.                                 end
  443.                         end
  444.                 end
  445.                 WHEN (argument = '-AUTOSTART') then do
  446.                         /*--------------------------------------------------*/
  447.                         /* Translate the argument value into uppercase.     */
  448.                         /*--------------------------------------------------*/
  449.                         arg_value = translate( arg_value )
  450.  
  451.                         /*--------------------------------------------------*/
  452.                         /* Check to see that the given parameter is either  */
  453.                         /* ON or OFF.  If not, display an error message and */
  454.                         /* quit.                                            */
  455.                         /*--------------------------------------------------*/
  456.                         if (arg_value = 'ON') then do
  457.                                 should_autostart = 1
  458.                         end
  459.                         else do
  460.                                 if (arg_value = 'OFF') then do
  461.                                         should_autostart = 0
  462.                                 end
  463.                                 else do
  464.                                         say 'Autostart requires either ON or OFF as a parameter.' || cr
  465.                                         exit 1
  466.                                 end
  467.                         end
  468.                 end
  469.                 WHEN (argument = '-ADDRESS') then do
  470.                         /*--------------------------------------------------*/
  471.                         /* Unfortunately, I can't do much error checking    */
  472.                         /* here.  So, we'll at least ensure that we have    */
  473.                         /* been given a value and that it is a string.  If  */
  474.                         /* not, display an error message and quit.          */
  475.                         /*--------------------------------------------------*/
  476.                         if ( (arg_value \= '') & (datatype(arg_value) = 'CHAR') ) then do
  477.                                 os2_address = arg_value
  478.                         end
  479.                         else do
  480.                                 say 'Address requires a dotted decimal notation address as a parameter.' || cr
  481.                                 exit 1
  482.                         end
  483.                 end
  484.         OTHERWISE do
  485.                 say 'Invalid command line argument: ' || argument || cr
  486.                 exit 1
  487.         end     /* END for the OTHERWISE statement                         */
  488.         END     /* END for the SELECT statement                            */
  489.  
  490.         /*------------------------------------------------------------------*/
  491.         /* Recurse to parse any remaining command line arguments.           */
  492.         /*------------------------------------------------------------------*/
  493.         call parse_arguments( arguments )
  494. return
  495.  
  496.  
  497. /*--------------------------------------------------------------------------*/
  498. /*                    waitfor ( waitstring , [timeout] )                    */
  499. /*..........................................................................*/
  500. /*                                                                          */
  501. /* Waits for the supplied string to show up in the COM input.  All input    */
  502. /* from the time this function is called until the string shows up in the   */
  503. /* input is accumulated in the "waitfor_buffer" variable.                   */
  504. /*                                                                          */
  505. /* If timeout is specified, it says how long to wait if data stops showing  */
  506. /* up on the COM port (in seconds).                                         */
  507. /*                                                                          */
  508. /*--------------------------------------------------------------------------*/
  509. waitfor:
  510.         parse arg waitstring , timeout
  511.  
  512.         if timeout = '' then timeout = 5000  /* LONG delay if not specified */
  513.  
  514.         waitfor_buffer = ''
  515.         done = -1
  516.         curpos = 1
  517.         ORI_TIME=TIME('E')
  518.  
  519.         if (remain_buffer = 'REMAIN_BUFFER') then do
  520.                 remain_buffer = ''
  521.         end
  522.  
  523.         do while (done = -1)
  524.                 if (remain_buffer \= '') then do
  525.                         line = remain_buffer
  526.                         remain_buffer = ''
  527.                 end
  528.                 else do
  529.                         line = slip_com_input(interface,,10)
  530.                 end
  531.  
  532.                 waitfor_buffer = waitfor_buffer || line
  533.                 index = pos(waitstring,waitfor_buffer)
  534.  
  535.                 if (index > 0) then do
  536.                         remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  537.                         waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  538.                         done = 0
  539.                 end
  540.  
  541.                 curpos = length(waitfor_buffer)+1
  542.  
  543.                 if ((done \= 0) & (TIME('E')>timeout)) then do
  544.                         done = 1
  545.                 end
  546.         end     /* end of 'while done = -1' */
  547.  
  548.         timeout=0
  549.         RC=done
  550. return RC
  551.  
  552.  
  553.  
  554. /*--------------------------------------------------------------------------*/
  555. /*                               readpass ()                                */
  556. /*..........................................................................*/
  557. /*                                                                          */
  558. /* Routine used to read a password from the user without echoing the        */
  559. /* password to the screen.                                                  */
  560. /*                                                                          */
  561. /*--------------------------------------------------------------------------*/
  562. readpass:
  563.         answer = ''
  564.  
  565.         do until key = cr
  566.                 key = slip_getch()
  567.  
  568.                 if key \= cr then do
  569.                         answer = answer || key
  570.                 end
  571.         end
  572.  
  573.         say ''
  574. return answer
  575.  
  576.  
  577. /*--------------------------------------------------------------------------*/
  578. /*                             flush_receive ()                             */
  579. /*..........................................................................*/
  580. /*                                                                          */
  581. /* Routine to flush any pending characters to be read from the COM port.    */
  582. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  583. /* point it returns.                                                        */
  584. /*                                                                          */
  585. /* The optional echo argument, if 1, says to echo flushed information.      */
  586. /*                                                                          */
  587. /*--------------------------------------------------------------------------*/
  588. flush_receive:
  589.         parse arg echo
  590.  
  591.         /* If echoing the flush - take care of waitfor remaining buffer     */
  592.         if (echo \= '') & (length(remain_buffer) > 0) then do
  593.                 call charout , remain_buffer
  594.                 remain_buffer = ''
  595.         end
  596.  
  597.         /* Eat anything left in the modem or COM buffers.  Stop when        */
  598.         /* new appears for 100ms.                                           */
  599.         do until line = ''
  600.                 line = slip_com_input(interface,,100)
  601.                 if echo \= '' then call charout , line
  602.         end
  603. return
  604.  
  605.  
  606.  
  607. /*--------------------------------------------------------------------------*/
  608. /* NOTE: The following two procedures (waitfor3, waitfor2) were written by  */
  609. /*       Harold Roussel (roussel@physics. mcgill.ca).                       */
  610. /*--------------------------------------------------------------------------*/
  611.  
  612. /*--------------------------------------------------------------------------*/
  613. /*    waitfor3 ( waitstring1 , waitstring2 , waitstring3)                   */
  614. /*..........................................................................*/
  615. /*                                                                          */
  616. /* Waits for the supplied strings to show up in the COM input.  All input   */
  617. /* from the time this function is called until the string shows up in the   */
  618. /* input is accumulated in the "waitfor_buffer" variable.                   */
  619. /*                                                                          */
  620. /*--------------------------------------------------------------------------*/
  621. /* modified to accomodate three strings                                     */
  622. /* this functions returns 1, 2, or 3 depending on which string was received */
  623. /* first                                                                    */
  624. /*--------------------------------------------------------------------------*/
  625. waitfor3:
  626.         parse arg waitstring1 , waitstring2 , waitstring3 , timeout
  627.  
  628.         waitfor_buffer = ''
  629.         done = 0
  630.         curpos = 1
  631.  
  632.         if (remain_buffer = 'REMAIN_BUFFER') then do
  633.                 remain_buffer = ''
  634.         end
  635.  
  636.         do while done = 0
  637.                 if (remain_buffer \= '') then do
  638.                         line = remain_buffer
  639.                         remain_buffer = ''
  640.                 end
  641.                 else do
  642.                         line = slip_com_input(interface)
  643.                 end
  644.  
  645.                 waitfor_buffer = waitfor_buffer || line
  646.                 index1 = pos(waitstring1,waitfor_buffer)
  647.                 index2 = pos(waitstring2,waitfor_buffer)
  648.                 index3 = pos(waitstring3,waitfor_buffer)
  649.  
  650.                 if (index1 > 0) then do
  651.                         remain_buffer = substr(waitfor_buffer,index1+length(waitstring1))
  652.                         waitfor_buffer = delstr(waitfor_buffer,index1+length(waitstring1))
  653.                         stringchosen = 1
  654.                         done = 1
  655.                 end
  656.                 else do
  657.                         if (index2 > 0) then do
  658.                                 remain_buffer = substr(waitfor_buffer,index2+length(waitstring2))
  659.                                 waitfor_buffer = delstr(waitfor_buffer,index2+length(waitstring2))
  660.                                 stringchosen = 2
  661.                                 done = 1
  662.                         end
  663.                         else do
  664.                                 if (index3 > 0) then do
  665.                                         remain_buffer = substr(waitfor_buffer,index3+length(waitstring3))
  666.                                         waitfor_buffer = delstr(waitfor_buffer,index3+length(waitstring3))
  667.                                         stringchosen = 3
  668.                                         done = 1
  669.                                 end
  670.                         end
  671.                 end
  672.  
  673.                 curpos = length(waitfor_buffer)+1
  674.         end
  675. return
  676.  
  677.  
  678.  
  679. /*--------------------------------------------------------------------------*/
  680. /*    waitfor2 ( waitstring1 , waitstring2 )                                */
  681. /*..........................................................................*/
  682. /*                                                                          */
  683. /* Waits for the supplied strings to show up in the COM input.  All input   */
  684. /* from the time this function is called until the string shows up in the   */
  685. /* input is accumulated in the "waitfor_buffer" variable.                   */
  686. /*                                                                          */
  687. /*--------------------------------------------------------------------------*/
  688. /* modified to accomodate a second string                                   */
  689. /* this functions returns 1 or 2 depending on which string was received     */
  690. /* first                                                                    */
  691. /*--------------------------------------------------------------------------*/
  692. waitfor2:
  693.         parse arg waitstring1 , waitstring2 , timeout
  694.  
  695.         waitfor_buffer = ''
  696.         done = 0
  697.         curpos = 1
  698.  
  699.         if (remain_buffer = 'REMAIN_BUFFER') then do
  700.                 remain_buffer = ''
  701.         end
  702.  
  703.         do while done = 0
  704.                 if (remain_buffer \= '') then do
  705.                         line = remain_buffer
  706.                         remain_buffer = ''
  707.                 end
  708.                 else do
  709.                         line = slip_com_input(interface)
  710.                 end
  711.  
  712.                 waitfor_buffer = waitfor_buffer || line
  713.                 index1 = pos(waitstring1,waitfor_buffer)
  714.                 index2 = pos(waitstring2,waitfor_buffer)
  715.  
  716.                 if (index1 > 0) then do
  717.                         remain_buffer = substr(waitfor_buffer,index1+length(waitstring1))
  718.                         waitfor_buffer = delstr(waitfor_buffer,index1+length(waitstring1))
  719.                         stringchosen = 1
  720.                         done = 1
  721.                 end
  722.                 else do
  723.                         if (index2 > 0) then do
  724.                                 remain_buffer = substr(waitfor_buffer,index2+length(waitstring2))
  725.                                 waitfor_buffer = delstr(waitfor_buffer,index2+length(waitstring2))
  726.                                 stringchosen = 2
  727.                                 done = 1
  728.                         end
  729.                 end
  730.  
  731.                 curpos = length(waitfor_buffer)+1
  732.         end
  733. return
  734.